I have a Vue2 Rails application and tried to install Jest which worked. The problem is that I cannot test my components because of this error:
● Test suite failed to run
Configuration error:
Could not locate module @/app.vue mapped as:
/Users/name/project/project-name/src/app.vue.
Please check your configuration for these entries:
{
"moduleNameMapper": {
"/^@\/(.*)$/": "/Users/name/project/project-name/src/$1"
},
"resolver": null
}
Which makes sense, because my component is in /Users/name/project/project-name/app/javascript/app.vue and there is no src directory in my project, because it is a Rails app.
But in my package.json I added
"jest": {
"moduleNameMapper": {
"^@/(.*)$": "<rootDir>/app/javascript/$1"
},
"preset": "@vue/cli-plugin-unit-jest/presets/no-babel"
}
Which obviously does not work. Putting all of it into a src folder also does not work. I feel like I'm missing some crucial configuration.
Edit: Alright, I went in and changed my moduleNameMapper by hand which is definitely not how this should be done, but I couldn't get it to work otherwise. In node_modules/jest-resolve/build/index.js at line 121 I wrote
this._options.moduleNameMapper[0].moduleName = "/Users/name/project/project-name/app/javascript/$1";
I don't have time to figure out the real issue right now. I will come back when I have the real solution.